<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/28
 * Time: 上午9:29
 */

namespace app\model;


class ShoppingCart extends Base
{
    protected $pk = 'id';
    // 此处表名请务必设置为public
    public $table = 'shopping_cart';

    /**
     * @purpose 管理商品模型
     * @return \think\model\relation\HasOne
     */
    public function goods () {
        return $this->hasOne('Goods', 'id', 'goods_id')
            ->bind('status');
    }
    /**
     * @purpose 通过条件获取数据数量
     * @param array $where
     * @return int
     */
    public function total (array $where): int
    {
        return (int) $this
            ->where($where)
            ->count();
    }
}